/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "char_race" )
@NamedQueries(
  {
    @NamedQuery( name = "CharRace.findByRaceId",
                  query = "SELECT c FROM CharRace c WHERE c.raceId = :raceId" ),
    @NamedQuery( name = "CharRace.findByRaceName",
                  query = "SELECT c FROM CharRace c WHERE c.raceName = :raceName" ),
    @NamedQuery( name = "CharRace.findByRaceDescr",
                  query = "SELECT c FROM CharRace c WHERE c.raceDescr = :raceDescr" ) } )
public class CharRace implements Serializable {
  private static final long serialVersionUID = 1L;
  private Integer raceId;
  private String raceName;
  private String raceDescr;
  private Collection<UserChar> userCharCollection;


  public CharRace() {
  }


  public CharRace( Integer raceId ) {
    this.raceId = raceId;
  }


  public CharRace( Integer raceId, String raceName ) {
    this.raceId = raceId;
    this.raceName = raceName;
  }


  @Id
  @GeneratedValue( strategy=GenerationType.SEQUENCE )
  @Column( name = "race_id", nullable = false )
  public Integer getRaceId() {
    return raceId;
  }


  public void setRaceId( Integer raceId ) {
    this.raceId = raceId;
  }


  @Column( name = "race_name", nullable = false, length = 20, unique = true )
  public String getRaceName() {
    return raceName;
  }


  public void setRaceName( String raceName ) {
    this.raceName = raceName;
  }


  @Column( name = "race_descr", length = 1024 )
  public String getRaceDescr() {
    return raceDescr;
  }


  public void setRaceDescr( String raceDescr ) {
    this.raceDescr = raceDescr;
  }


  @OneToMany( cascade = CascadeType.ALL, mappedBy = "raceId" )
  public Collection<UserChar> getUserCharCollection() {
    return userCharCollection;
  }


  public void setUserCharCollection( Collection<UserChar> userCharCollection ) {
    this.userCharCollection = userCharCollection;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += ( raceId != null ? raceId.hashCode() : 0 );
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof CharRace ) ) {
      return false;
    }
    CharRace other = (CharRace) object;
    if ( ( this.raceId == null && other.raceId != null ) || ( this.raceId != null && !this.raceId.equals( other.raceId ) ) ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.CharRace[raceId=" + raceId + "]";
  }

}
